package com.central.scheduler.dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Tindy
 * @date 2021/10/29
 * @describe
 */
public class DaoFactory {

    private static final Logger logger = LoggerFactory.getLogger(DaoFactory.class);

    private static Map<String, AbstractBaseDao> daoMap = new ConcurrentHashMap<>();

    private DaoFactory(){

    }

    /**
     * get dao instance
     * @param clazz clazz
     * @param <T> T
     * @return T object
     */
    @SuppressWarnings("unchecked")
    public static <T extends AbstractBaseDao> T getDaoInstance(Class<T> clazz) {
        String className = clazz.getName();
        return (T) daoMap.get(className);
    }

    public static void putDaoInstance(AbstractBaseDao dao){
        daoMap.put(dao.getClass().getName(),dao);
    }
}

